﻿using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.DB
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class Product_TypeController : ControllerBase
    {
        private readonly IDb_Product_TypeService product_TypeService;
        private readonly IMapper mapper;

        public Product_TypeController(IDb_Product_TypeService product_TypeService,IMapper mapper)
        {
            this.product_TypeService = product_TypeService;
            this.mapper = mapper;
        }

        /// <summary>
        /// 条件分页查询产品信息
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="typeName"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetProduct_Types(int currentPage, int pageSize, string? typeName, char status)
        {
            return new JsonResult(product_TypeService.GetProduct_Types(currentPage,pageSize,typeName,status));
        }

        /// <summary>
        /// 条件查询产品信息
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Product_TypeCount(string? typeName, char status)
        {
            return new JsonResult(product_TypeService.Product_TypeCount(typeName,status));
        }

        /// <summary>
        /// 判断产品分类序号是否唯一
        /// </summary>
        /// <param name="sort"></param>
        /// <param name="parentId"></param>
        /// <param name="proTypeId"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult CheckSortUnique(int sort, int parentId, int proTypeId)
        {
            return new JsonResult(product_TypeService.CheckSortUnique(sort,parentId, proTypeId));
        }

        /// <summary>
        /// 添加产品分类信息
        /// </summary>
        /// <param name="product_TypeAddDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> Product_TypeAddAsync(Db_Product_TypeAddDto product_TypeAddDto)
        {
            return new JsonResult(await product_TypeService.Product_TypeAddAsync(product_TypeAddDto));
        }

        /// <summary>
        /// 修改产品分类信息
        /// </summary>
        /// <param name="product_TypeUpdateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Product_TypeUpdateAsync(Db_Product_TypeUpdateDto product_TypeUpdateDto)
        {
            return new JsonResult(await product_TypeService.Product_TypeUpdateAsync(product_TypeUpdateDto));
        }

        /// <summary>
        /// 逻辑删除产品分类信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Product_TypeDeleteAsync([FromBody] List<Db_Product_TypeDelDto> product_TypeDelDto)
        {
            return new JsonResult(await product_TypeService.Product_TypeDeleteAsync(product_TypeDelDto));
        }
    }
}
